package org.monster.context.util;

/**
 * URI工具
 *
 * @author Monster
 */
public class URIUtils {

    /**
     * 开始字符串
     * 获取URI中首个字符串，到/为止。
     *
     * @param uri uri
     * @return 字符串
     */
    public static String startWithURI(String uri) {
        String[] split = uri.split("\u002f"); // --> /
        if (split.length < 2)
            return uri;
        else
            return split[1];
    }

    /**
     * 结束URI
     *
     * @param str    字符串
     * @param symbol 符号
     * @return 字符串
     */
    public static String endsWithURI(String str, String symbol) {
        return str.substring(str.lastIndexOf(symbol) + 1, str.length());
    }

    /**
     * 获取URI中首个/字符到结尾的字符串
     *
     * @param uri
     * @return
     */
    public static String allEndsWithURI(String uri) {
        if (uri != null) {
            String[] split = uri.split("\u002f");
            if (split.length > 2) {
                if (split.length >= 3) {
                    String path = "";
                    for (int i = 2; i < split.length; i++) {
                        path += "/" + split[i];
                    }
                    return path;
                }
                return "/" + split[2];
            } else
                return uri;
        }
        return null;
    }
}